/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package server.so.dolazak;

import domen.Dolazak;
import domen.OpstiDomenskiObjekat;
import java.util.Iterator;
import java.util.LinkedList;
import server.baza.DataBaseBroker;
import server.so.OpstaSO;

/**
 *
 * @author Ivan Ivic
 */
public class VratiDolaske extends OpstaSO {
    private LinkedList<Dolazak> listaDolazaka;

    public LinkedList<Dolazak> getListaDolazaka() {
        return listaDolazaka;
    }
    
    public synchronized static LinkedList<Dolazak> vratiDolaske(Dolazak d)
    {
        VratiDolaske vd = new VratiDolaske();
        vd.opsteIzvrsenjeSO(d);
        return vd.getListaDolazaka();
    }

    @Override
    public int izvrsenjeSO(OpstiDomenskiObjekat odo) {
        Dolazak d = (Dolazak) odo;
        listaDolazaka = new LinkedList<Dolazak>();
        LinkedList<OpstiDomenskiObjekat> l = new LinkedList<OpstiDomenskiObjekat>();
//        /LinkedList<Dolazak> ld = new LinkedList<Dolazak>();

        l = DataBaseBroker.getDbb().pronadji(d);
        Iterator it = l.iterator();
        while (it.hasNext()) {
            listaDolazaka.add((Dolazak) it.next());
            //ld.add((Dolazak) it.next());
        }
        /*Trening t = new Trening();
        t.setSifraTreninga(d.getSifraTreninga());
        t = (Trening) DataBaseBroker.getDbb().vrati(t);
        int maxBrojDolazaka = t.getBrojTermina();
        if (ld.size() > maxBrojDolazaka)
        {
        int pocBroj = (ld.size() % maxBrojDolazaka) * maxBrojDolazaka;
        for (int i = pocBroj; i < ld.size(); i++)
        {
        listaDolazaka.add(ld.get(i));
        }
        }
        else
        listaDolazaka.addAll(ld);
         *
         */
        //signal = 9015;
        signal = DataBaseBroker.getDbb().getSignal();

        return signal;
    }

    @Override
    public boolean stanjeOperacije(int signal) {
        switch (signal)
        {
            case 9015:
                prikazi(signal, "Slogovi uspesno vraceni");
                return true;
            case 9016:
                prikazi(signal, "Slogovi nisu uspesno vraceni");
                return false;
            default:
                return false;
        }
    }
}
